
package com.base.app_core.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.base.app_core.R;
import com.blankj.utilcode.util.StringUtils;

/**
 * 对话框的统一类 Created by Administrator on 2016/5/6.
 */
public final class DialogHelper {
    // static DialogHelper mDialogUtil = new DialogHelper();

    // public DialogHelper getInstance() {

    public DialogHelper() {

    }

	public static void showInputErrorMemo(Activity context, final onInputClickListener onClickListener) {
        if (context == null) {
            return;
        }
        final Dialog _dialog = new Dialog(context, R.style.custom_dialog);
        View _view = context.getLayoutInflater().inflate(R.layout.layout_simpledialog_input, null);
        Button reset = (Button) _view.findViewById(R.id.reset);
        Button submit = (Button) _view.findViewById(R.id.submit);
        final EditText content = (EditText) _view.findViewById(R.id.content);
        reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dismissDialog(_dialog);
            }
        });
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickListener.onMessage(content.getText().toString());
                dismissDialog(_dialog);
            }
        });
        _dialog.setContentView(_view);
        _dialog.setCancelable(true);
        showDialog(context, _dialog);
	}


	public interface DialogBtnClick {
        public void onClick(int pos);

    }

    public static void showSelectOkCancel(Activity context, String Content,
                                          String cancelTex, String submitTex, final onItemClickLisener dialogBtnClick) {
        if (context == null) {
            return;
        }
        final Dialog _dialog = new Dialog(context, R.style.custom_dialog);
        View _view = context.getLayoutInflater().inflate(R.layout.layout_simpledialog_okcancel, null);
        Button reset = (Button) _view.findViewById(R.id.reset);
        reset.setText(cancelTex);
        Button submit = (Button) _view.findViewById(R.id.submit);
        submit.setText(submitTex);
        TextView content = (TextView) _view.findViewById(R.id.content);
        if (!StringUtils.isEmpty(Content)) {
            content.setText(Content);
        }
        reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != dialogBtnClick)
                    dialogBtnClick.onItemClick(false);
                dismissDialog(_dialog);
            }
        });
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != dialogBtnClick)
                    dialogBtnClick.onItemClick(true);
                dismissDialog(_dialog);
            }
        });
        _dialog.setContentView(_view);
        _dialog.setCancelable(true);
        showDialog(context, _dialog);
    }


    private static void startToSettting(Activity context) {
        Intent wifiSettingsIntent = new Intent(Settings.ACTION_SETTINGS);
        context.startActivity(wifiSettingsIntent);
    }

    private static void dismissDialog(Dialog dialog) {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    private static void showDialog(Activity context, Dialog dialog) {
        if (!context.isFinishing() && dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    public interface onItemClickLisener {
        void onItemClick(boolean position);
    }
    public interface  onInputClickListener{
        void onMessage(String content);
    }
}
